package com.bj.dz.service.impl;

import com.bj.dz.entity.CorrespondImportBuilding;
import com.bj.dz.mapper.CorrespondImportBuildingMapper;
import com.bj.dz.service.CorrespondImportBuildingService;
import com.bj.dz.util.Constants;
import com.bj.dz.util.EmptyUtils;
import com.bj.dz.util.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class CorrespondImportBuildingServiceImpl implements CorrespondImportBuildingService {

    @Resource
    private CorrespondImportBuildingMapper correspondImportBuildingMapper;

    public CorrespondImportBuilding getCorrespondImportBuildingById(Integer id){
        return correspondImportBuildingMapper.getCorrespondImportBuildingById(id);
    }

    public List<CorrespondImportBuilding>	getCorrespondImportBuildingListByMap(Map<String,Object> param){
        return correspondImportBuildingMapper.getCorrespondImportBuildingListByMap(param);
    }

    public Integer getCorrespondImportBuildingCountByMap(Map<String,Object> param){
        return correspondImportBuildingMapper.getCorrespondImportBuildingCountByMap(param);
    }

    @Transactional
    public boolean addCorrespondImportBuilding(CorrespondImportBuilding correspondImportBuilding){
            return correspondImportBuildingMapper.insertCorrespondImportBuilding(correspondImportBuilding)>0?true:false;
    }

    @Transactional
    public boolean modifyCorrespondImportBuilding(CorrespondImportBuilding correspondImportBuilding){
        return correspondImportBuildingMapper.updateCorrespondImportBuilding(correspondImportBuilding)>0?true:false;
    }

    @Transactional
    public boolean deleteCorrespondImportBuildingById(Integer id){
        return correspondImportBuildingMapper.deleteCorrespondImportBuildingById(id)>0?true:false;
    }

    public Page<CorrespondImportBuilding> queryCorrespondImportBuildingPageByMap(Map<String,Object> param, Integer pageNo, Integer pageSize){
        Integer total = correspondImportBuildingMapper.getCorrespondImportBuildingCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<CorrespondImportBuilding> correspondImportBuildingList = correspondImportBuildingMapper.getCorrespondImportBuildingListByMap(param);
        page.setRows(correspondImportBuildingList);
        return page;
    }

}
